package team.archai.nexus.boot.tool;

import cn.hutool.setting.yaml.YamlUtil;

import java.util.List;
import java.util.Map;

/**
 * @author li shibin
 */
public class YamlUtils extends YamlUtil {


    @SuppressWarnings("unchecked")
    public static void mergeMaps(Map<String, Object> base, Map<String, Object> custom, String startKey) {
        for (String key : custom.keySet()) {
            if (base.containsKey(key) && base.get(key) instanceof Map && custom.get(key) instanceof Map) {
                mergeMaps((Map<String, Object>) base.get(key), (Map<String, Object>) custom.get(key), startKey);
            } else if (base.containsKey(key) && base.get(key) instanceof List && custom.get(key) instanceof List) {
                ((List<Object>) base.get(key)).addAll((List<Object>) custom.get(key));
            } else {
                base.put(key, custom.get(key));
            }
        }
    }
}
